---
title: 'Lutscher & Donnay, _Perspectives on Politics_'
author: "Philipp Lutscher, Karsten Donnay"
date: "2024-11-05"
output: html_document
---

## Replication Information -- Does Hard Propaganda (Also) Work in Democracies? Evidence from the United States

### Import Pakages

```{r packages}
#### Loading packages ####
library(cjoint)
library(tidyverse)
library(xtable)
library(texreg)
library(gridExtra)
library(broom)
library(estimatr)
```


### Setup Design
```{r setup}
##### Build simple design ####
attribute_list <- list()
attribute_list[["picture"]] <-c("control","propaganda")
marginal_weights <- list() # two pictures in propaganda
marginal_weights[["picture"]] <- c(1/3,2/3) #How likely that they will appear
propagandadesign_simple <- makeDesign(type='constraints', attribute.levels=attribute_list,
                                      level.probs=marginal_weights)

#With individual groups
attribute_list <- list()
attribute_list[["picture_dis"]] <-c("control","bureaucrats",
                                    "police")

propagandadesign_simple_diss <- makeDesign(type='constraints', attribute.levels=attribute_list)
baselines <- list()
baselines$picture_dis <- "control"
```

### Import and Prepare Data
```{r data}
#### Load data ####

export <- read_delim("export.csv", ";", escape_double = FALSE, 
                       col_types = cols(date_of_first_mail = col_character()), 
                       trim_ws = TRUE)

#Remove non-participants
export <- filter(export,v_108=="I accept" & v_109!=-77)

#Define groups
export <- export %>% mutate(
  group = ifelse(v_43!=-77 | v_176!=-77,"bc","NA"),
  group = ifelse(v_146!=-77 | v_182!=-77,"cb",group),
  group = ifelse(v_152!=-77 | v_188!=-77,"cp",group),
  group = ifelse(v_158!=-77 | v_194!=-77,"pc",group),
  group = ifelse(v_164!=-77 | v_200!=-77 ,"pb",group),
  group = ifelse(v_170!=-77 | v_206!=-77,"bp",group),
  anti = ifelse(v_109 %in% c("Very unlikely", "Unlikely","Somehow unlikely"),1,0))

export <- export %>% mutate(
  group_together = case_when(group=="bc" | group=="cb" ~ "bureaucrats_control",
                             group=="cp" | group=="pc" ~ "police_control",
                             group=="pb" | group=="bp"~ "bureaucrats_police"))

#Define Covariats
export <- export %>% mutate(
  bureaucrats_control =  if_else(group_together=="bureaucrats_control",1,0),
  police_control = if_else(group_together=="police_control",1,0),
  bureaucrats_police = if_else(group_together=="bureaucrats_police",1,0),
  #Gender
  male = if_else(v_1=="Male",1,0),
  #Ethnicity
  aa = if_else(v_29=="Black or African American",1,0),
  white = if_else(v_29=="White or Caucasian",1,0),
  latino = if_else(v_29=="Hispanic or Latino",1,0),
  other = if_else(aa!=1 & white!=1 & latino!=1,1,0),
  #Age
  old = if_else(v_21=="Older than 60",1,0),
  #Affiliation
  democrat = if_else(v_89=="Democract",1,0),
  republican = if_else(v_89=="Republican",1,0),
  independet =  if_else(v_89=="Independent",1,0),
  
  #Education (treat as continuous variable)
  high_school = if_else(v_30=="High school degree or equivalent",1,0),
  bachelor = if_else(v_30=="Bachelor degree",1,0),
  master = if_else(v_30=="Graduate degree or higher",1,0),
  less =  if_else(v_30=="Less than high school degree",1,0),
  highed= if_else(bachelor==1 | master==1,1,0),
  
  #Urban/suburban
  urban =if_else(v_32=="Urban",1,0),
  suburban =if_else(v_32=="Suburban",1,0),
  rural =if_else(v_32=="Rural",1,0),
  
  #Media consumption
  news_veroften =if_else(v_33=="Daily",1,0),
  news_often =if_else(v_33=="Several times a week",1,0),
  news_unoften =if_else(v_33=="Several times a month",1,0),
  news_never =if_else(v_33=="Never",1,0),
  news_almnever = if_else(news_unoften==1 | news_never==1,1,0)
)

#Construct groups
export <- export %>% mutate(
  ethnic_group_sig = case_when(v_29=="Black or African American" ~ "African American",
                               v_29=="Hispanic or Latino" ~ "Latino",
                               v_29=="White or Caucasian" ~ "White",
                             v_29!="Black or African American" | v_29!="Hispanic or Latino" | v_29!="White or Caucasian" ~ "Other"))

```

## Main Analysis

### Create dataset for main analysis
```{r create dataset}
#Load Helper functions
source("helper_functions.R")

##### Pro Group #####
#Transform data frame

pro_bc_df_final <- transform_df("propaganda","bureaucrats","control","control",
                "v_43","v_86","v_101","v_100","v_140","v_106",
                filter(export,v_43!=-77))

pro_cb_df_final <- transform_df("control","control","propaganda","bureaucrats",
                                "v_146","v_147","v_148","v_149","v_150","v_151",
                                filter(export,v_146!=-77))

pro_cp_df_final <- transform_df("control","control","propaganda","police",
                                "v_152","v_153","v_154","v_155","v_156","v_157",
                                filter(export,v_152!=-77))

pro_pc_df_final <- transform_df("propaganda","police","control","control",
                                "v_158","v_159","v_160","v_161","v_162","v_163",
                                filter(export,v_158!=-77))

pro_pb_df_final <- transform_df("propaganda","police","propaganda","bureaucrats",
                                "v_164","v_165","v_166","v_167","v_168","v_169",
                                filter(export,v_164!=-77))

pro_bp_df_final <- transform_df("propaganda","bureaucrats","propaganda","police",
                                "v_170","v_171","v_172","v_173","v_174","v_175",
                                filter(export,v_170!=-77))

pro_df <- rbind(pro_bc_df_final,pro_cb_df_final,
                pro_pc_df_final,pro_cp_df_final,
                pro_bp_df_final,pro_pb_df_final)


##### Anti Group #####
anti_bc_df_final <- transform_df("propaganda","bureaucrats","control","control",
                                "v_176","v_177","v_178","v_179","v_180","v_181",
                                filter(export,v_176!=-77))

anti_cb_df_final <- transform_df("control","control","propaganda","bureaucrats",
                                "v_182","v_183","v_184","v_185","v_186","v_187",
                                filter(export,v_182!=-77))

anti_cp_df_final <- transform_df("control","control","propaganda","police",
                                "v_188","v_189","v_190","v_191","v_192","v_193",
                                filter(export,v_188!=-77))

anti_pc_df_final <- transform_df("propaganda","police","control","control",
                                "v_194","v_195","v_196","v_197","v_198","v_199",
                                filter(export,v_194!=-77))

anti_pb_df_final <- transform_df("propaganda","police","propaganda","bureaucrats",
                                "v_200","v_201","v_202","v_203","v_204","v_205",
                                filter(export,v_200!=-77))

anti_bp_df_final <- transform_df("propaganda","bureaucrats","propaganda","police",
                                "v_206","v_207","v_208","v_209","v_210","v_211",
                                filter(export,v_206!=-77))


anti_df <- rbind(anti_bc_df_final,anti_cb_df_final,
                anti_cp_df_final,anti_pc_df_final,
                anti_bp_df_final,anti_pb_df_final)

#Combine dataset

final_perception_df <- rbind(pro_df,anti_df)

#Remove unnecessary data frames
rm(list= grep("pro_",names(.GlobalEnv),value=TRUE) )
rm(list= grep("anti_",names(.GlobalEnv),value=TRUE) )


#Recode Rating variables
range01 <- function(x){(x-min(x,na.rm=T))/(max(x,na.rm=T)-min(x,na.rm = T))}


final_perception_df <- final_perception_df %>% mutate(rating_stronger_numeric=
                                case_when(rating_stronger=="Very poorly" ~ 1,
                                          rating_stronger=="Poorly" ~ 2,
                                          rating_stronger=="Somehow poorly" ~ 3,
                                          rating_stronger=="Somehow well" ~ 4,
                                          rating_stronger=="Well" ~ 5,
                                          rating_stronger=="Very well" ~ 6)) %>%
  mutate(rating_stronger_numeric_z = range01(rating_stronger_numeric)) %>%
  mutate(rating_protest_numeric=case_when(rating_protest=="I would never participate" ~ 0,
                                          rating_protest=="Very unlikely" ~ 1,
                                          rating_protest=="Unlikely" ~ 2,
                                          rating_protest=="Somehow unlikely" ~ 3,
                                          rating_protest=="Somehow likely" ~ 4,
                                          rating_protest=="Likely" ~ 5,
                                          rating_protest=="Very likely" ~ 6
  )) %>%
  mutate(rating_protest_numeric_z = range01(rating_protest_numeric))

#Percentage of pro Trump: 41%

#Percentage of anti Trump: 59%
```

### Figure 3 (Perceptions of strength, political strength, appropriateness, mobilization potential)
```{r main, fig.width = 11, fig.height = 9}
#Main analysis
final_perception_df$picture <- as.factor(final_perception_df$picture)
final_perception_df$picture_dis <- as.factor(final_perception_df$picture_dis)
final_perception_df$picture_dis <- relevel(final_perception_df$picture_dis,"control")

final_perception_df$anti <- as.factor(final_perception_df$anti)
final_perception_df$Trump <- final_perception_df$anti

#Set levels
levels(final_perception_df$Trump) <-  c("Supporter","Opponent")

results_strength_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*Trump, data=final_perception_df)

results_strength <- amce(chose_stronger~  picture_dis+picture_dis*Trump, data=final_perception_df, 
                  cluster=TRUE, respondent.id="id",
                  respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength <- amce_plot_same(summary(results_strength),results_strength_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                           "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


results_strength_rating_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Trump, data=final_perception_df)

results_strength_rating <- amce(rating_stronger_numeric_z ~  picture_dis+picture_dis*Trump, data=final_perception_df, 
                         cluster=TRUE, respondent.id="id",
                         respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating <- amce_plot_same(summary(results_strength_rating),results_strength_rating_i,"(b) Political Strength","Difference in Strength Perception (Rating)",
                                       "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_appropiate_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*Trump, data=final_perception_df)

results_appropiate <- amce(chose_appropiate~  picture_dis+picture_dis*Trump, data=final_perception_df, 
                  cluster=TRUE, respondent.id="id",
                  respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate <- amce_plot_same(summary(results_appropiate),results_appropiate_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                           "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Trump, data=final_perception_df)

results_protest <- amce(rating_protest_numeric_z ~  picture_dis+picture_dis*Trump, data=final_perception_df, 
                  cluster=TRUE, respondent.id="id",
                  respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_protest <- amce_plot_same(summary(results_protest),results_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                          "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


grid.arrange(plot_strength,plot_strength_rating,plot_appropiate,plot_protest,ncol = 1)
dev.print(pdf,"figures/figure_3_main_results.pdf",width=11, height=9)

#Report result in a table 
amce_latex(summary(results_strength),summary(results_strength_rating),summary(results_appropiate),summary(results_protest),
           "Trump Supporters","Trump Opponents",no_outcomes=4, file_name = "tables/table_d1_main_results_p1.tex")

texreg(list(results_strength_i,results_strength_rating_i,results_appropiate_i,results_protest_i),
       file = "tables/table_d1_main_results_p2.tex")

```


### Figure 4 (absolute ratings)
```{r absolute, fig.width = 8, fig.height = 4}
####Absolute Ratings (Figure 4) ####
#Table per Outcome (Strength Perception, Appropriateness and Protest Willingness)

perception_df <- mutate(final_perception_df,picture_dis = case_when(
  picture_dis == "bureaucrats" ~ "Bureaucrats",
  picture_dis == "control" ~ "Reference",
  picture_dis == "police" ~ " Police"
))

summary_df_strenght <-
  final_perception_df %>% group_by(Trump, picture_dis) %>%
  do(tidy(lm(rating_stronger_numeric ~ 1, data = .))) %>% #run lm for every group
  mutate(rating_stronger_numeric = estimate,
         conf.low = estimate - 1.96*std.error,
         conf.high = estimate + 1.96*std.error,
  )

summary_plot_strenght <- ggplot(final_perception_df, aes(Trump, rating_stronger_numeric)) +
  geom_point(position = position_jitter(width = .25, height = .1), alpha = 0.1, stroke = 0) +
  facet_wrap( ~ picture_dis) +
  geom_point(data = summary_df_strenght, size = 4) +
  geom_errorbar(data = summary_df_strenght,
                aes(ymin = conf.low, ymax = conf.high),
                width = 0) +
  scale_y_continuous(breaks = c(1,2,3,4,5,6)) +
  theme_bw() +
  theme(strip.text = element_text(size=12),
        plot.title = element_text(color="black", size=14, face="bold"),
        legend.position="none",
        strip.text.x =  element_text(size=12),
        panel.spacing.x = unit(10, "mm"),
        axis.title.x = element_blank()) +
  ylab("1 = very poorly - 6 = very well") +
  ggtitle("Political Strength (rating)")
summary_plot_strenght
dev.print(pdf,"figures/figure_4_rating_absolute_p1.pdf",width = 8, height = 4)

summary_df_protest <-
  final_perception_df %>% group_by(Trump, picture_dis) %>%
  do(tidy(lm(rating_protest_numeric ~ 1, data = .))) %>% #run lm for every group
  mutate(rating_protest_numeric = estimate,
         conf.low = estimate - 1.96*std.error,
         conf.high = estimate + 1.96*std.error,
  )

summary_plot_protest <- ggplot(final_perception_df, aes(Trump, rating_protest_numeric)) +
  geom_point(position = position_jitter(width = .25, height = .1), alpha = 0.1, stroke = 0) +
  facet_wrap( ~ picture_dis) +
  geom_point(data = summary_df_protest, size = 4) +
  geom_errorbar(data = summary_df_protest,
                aes(ymin = conf.low, ymax = conf.high),
                width = 0) +
  scale_y_continuous(breaks = c(0,1,2,3,4,5,6)) +
  theme_bw() +
  theme(strip.text = element_text(size=12),
        plot.title = element_text(color="black", size=14, face="bold"),
        legend.position="none",
        strip.text.x =  element_text(size=12),
        panel.spacing.x = unit(10, "mm"),
        axis.title.x = element_blank()) +
  ylab("0 = I would never - 6 = I would very likely participate") +
  ggtitle("Mobilization potential (rating)")
summary_plot_protest
dev.print(pdf,"figures/figure_4_rating_absolute_p2.pdf",width = 8, height = 4)
```


### Figure 5 (subgroup analysis: news consumption, Trump opponents)
```{r media, fig.width = 11, fig.height = 9}
##### Media consumption #####
final_perception_df$Media <- as.factor(final_perception_df$media)

#Trump opponents
results_news_anti_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Opponent"))

results_news_anti <- amce(chose_stronger~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Opponent"), 
                  cluster=TRUE, respondent.id="id",
                  respondent.varying ="Media",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_media_a <- amce_plot_same(summary(results_news_anti),results_news_anti_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
          "Frequent News Consumers","Infrequent News Consumers","Infrequent-Frequent\n Difference")

results_news_anti_rat_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_rat <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Opponent"), 
                          cluster=TRUE, respondent.id="id",
                          respondent.varying ="Media",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_media_rat_a <- amce_plot_same(summary(results_news_anti_rat),results_news_anti_rat_i,"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                                       "Frequent News Consumers","Infrequent News Consumers","Infrequent-Frequent\n Difference")

results_news_anti_app_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_app <- amce(chose_appropiate~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Opponent"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="Media",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate_media_a <- amce_plot_same(summary(results_news_anti_app),results_news_anti_app_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                     "Frequent News Consumers","Infrequent News Consumers","Infrequent-Frequent\n Difference")

results_news_anti_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_protest <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Opponent"), 
                                  cluster=TRUE, respondent.id="id",
                                  respondent.varying = "Media",design=propagandadesign_simple_diss,baselines = baselines)

plot_news_protest_a <- amce_plot_same(summary(results_news_anti_protest),results_news_anti_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                                 "Frequent News Consumers","Infrequent News Consumers","Infrequent-Frequent\n Difference")

#Plot
grid.arrange(plot_strength_media_a,plot_strength_media_rat_a,plot_appropiate_media_a,plot_news_protest_a,ncol = 1)
dev.print(pdf,"figures/figure_5_media_anti.pdf",width = 11, height = 9)
```


### Figure 6 (subgroup analysis: Black/Others, Trump opponents)
```{r black anti, fig.width = 11, fig.height = 9}
##### Ethnic group within Trump Opponents #####
final_perception_df <- final_perception_df %>% mutate(AA=ifelse(ethnic_group_sig=="African American","African American","Other"))
final_perception_df$AA <- as.factor(final_perception_df$AA)

#Anti
results_a_anti_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*AA, data=filter(final_perception_df,Trump=="Opponent"))

results_a_anti <- amce(chose_stronger~  picture_dis+picture_dis*AA, data=filter(final_perception_df,Trump=="Opponent"), 
                          cluster=TRUE, respondent.id="id",
                          respondent.varying ="AA",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_a_a <- amce_plot_same(summary(results_a_anti),results_a_anti_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                    "Black","Other","Other-Black\n Difference")

results_a_anti_rat_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*AA, data=filter(final_perception_df,Trump=="Opponent"))
results_a_anti_rat <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*AA, data=filter(final_perception_df,Trump=="Opponent"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="AA",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_a_rat_a <- amce_plot_same(summary(results_a_anti_rat),results_a_anti_rat_i,"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                                        "Black","Other","Other-Black\n Difference")

results_a_anti_app_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*AA, data=filter(final_perception_df,Trump=="Opponent"))
results_a_anti_app <- amce(chose_appropiate~  picture_dis+picture_dis*AA, data=filter(final_perception_df,Trump=="Opponent"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="AA",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate_a_a <- amce_plot_same(summary(results_a_anti_app),results_a_anti_app_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                      "Black","Other","Other-Black\n Difference")

results_a_anti_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*AA, data=filter(final_perception_df,Trump=="Opponent"))
results_a_anti_protest <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*AA, data=filter(final_perception_df,Trump=="Opponent"), 
                                  cluster=TRUE, respondent.id="id",
                                  respondent.varying = "AA",design=propagandadesign_simple_diss,baselines = baselines)

plot_a_protest_a <- amce_plot_same(summary(results_a_anti_protest),results_a_anti_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                                      "Black","Other","Other-Black\n Difference")

#Plot
grid.arrange(plot_strength_a_a,plot_strength_a_rat_a,plot_appropiate_a_a,plot_a_protest_a,ncol = 1)
dev.print(pdf,"figures/figure_6_aa_anti.pdf",width = 11, height = 9)
```


### Figure 7 (subgroup analysis: party, Trump opponents)
```{r party anti, fig.width = 11, fig.height = 9}
##### Party #####
final_perception_df$party <- as.factor(final_perception_df$party)
levels(final_perception_df$party) <-  c("Democrat","Independent","Republican")

results_party_cs <- amce(chose_stronger~  picture_dis+picture_dis*party, data=final_perception_df, 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="party",design=propagandadesign_simple_diss,baselines = baselines)

plot_party_cs <- amce_plot_2(summary(results_party_cs),"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                "Unconditional","Democrat","Independent","Republican")

results_party_cs_rat <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*party, data=final_perception_df, 
                         cluster=TRUE, respondent.id="id",
                         respondent.varying ="party",design=propagandadesign_simple_diss,baselines = baselines)

plot_party_cs_rat <- amce_plot_2(summary(results_party_cs_rat),"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                             "Unconditional","Democrat","Independent","Republican")


results_party_ca <- amce(chose_appropiate~  picture_dis+picture_dis*party, data = final_perception_df, 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="party",design=propagandadesign_simple_diss,baselines = baselines)

plot_party_ca <- amce_plot_2(summary(results_party_ca ),"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                             "Unconditional","Democrat","Independent","Republican")


results_party_pw <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*party, data = final_perception_df, 
                             cluster=TRUE, respondent.id="id",
                             respondent.varying ="party",design=propagandadesign_simple_diss,baselines = baselines)
plot_party_pw <- amce_plot_2(summary(results_party_pw),"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                                "Unconditional","Democrat","Independent","Republican")

#Plot
grid.arrange(plot_party_cs,plot_party_cs_rat,plot_party_ca,plot_party_pw,ncol = 1)
dev.print(pdf,"figures/figure_7_party.pdf",width = 11, height = 9)
```


## Appendix B

### Correlation Tests (as reported in Online Appendix B) 
```{r correlations}
m1 <- lm(bureaucrats_control~anti+democrat+male+republican+latino+white+aa+
           highed+suburban+urban+news_almnever+news_often+factor(v_31)+factor(v_21),data=export)

m2 <- lm(police_control~anti+democrat+male+republican+latino+white+aa+
           highed+suburban+urban+news_almnever+news_often+factor(v_31)+factor(v_21),data=export)

m3 <- lm(bureaucrats_police~anti+democrat+male+republican+latino+white+aa+
           highed+suburban+urban+news_almnever+news_often+factor(v_31)+factor(v_21),data=export)

m1a <- lm(bureaucrats_control~democrat+male+republican+latino+white+aa+
            highed+suburban+urban+news_almnever+factor(v_31)+factor(v_21),data=filter(export,anti==1))

m2a <- lm(police_control~democrat+male+republican+latino+white+aa+
            highed+suburban+urban+news_almnever+factor(v_31)+factor(v_21),data=filter(export,anti==1))

m3a <- lm(bureaucrats_police~democrat+male+republican+latino+white+aa+
            highed+suburban+urban+news_almnever+factor(v_31)+factor(v_21),data=filter(export,anti==1))

m1p <- lm(bureaucrats_control~democrat+male+republican+latino+white+aa+
            highed+suburban+urban+news_almnever+factor(v_31)+factor(v_21),data=filter(export,anti==0))

m2p <- lm(police_control~democrat+male+republican+latino+white+aa+
            highed+suburban+urban+news_almnever+factor(v_31)+factor(v_21),data=filter(export,anti==0))

m3p <- lm(bureaucrats_police~democrat+male+republican+latino+white+aa+
            highed+suburban+urban+news_almnever+factor(v_31)+factor(v_21),data=filter(export,anti==0))

texreg::texreg(list(m1,m2,m3,m1p,m2p,m3p,m1a,m2a,m3a),file = "tables/table_b5_balance.tex",
custom.coef.map = list('democrat'="Democrat",'republican'="Republican",'male'="Male",
                       'factor(v_21)21 - 29' = "Age (21-29)",'factor(v_21)30 - 39' = "
                              Age (30-39)", 'factor(v_21)40 - 49' = "Age (40-49)",
                       'factor(v_21)50 - 59' = "Age (50-59)", 'factor(v_21)Older than 60'=
                         "Age (older than 60)", 'latino'="Latino",'aa'="African American",
                       'white'="Caucasian",'highed'="Higher education",
                       'master'="Graduate degree or higher",'suburban'="Sub-urban",
                       'urban'="Urban", "news_almnever" ="Infrequent news consumer"
                       
))
```

### Figure B2 (voting)
```{r voting intentions, fig.width = 8, fig.height = 4}
#Show distribution of Voting intention variable for Appendix
export$v_109 <- factor(export$v_109,levels=c("Very unlikely","Unlikely","Somehow unlikely",
                                                 "Somehow likely","Likely","Very likely"))

levels(export$v_109)[levels(export$v_109 )=='Somehow likely'] <- 'Somewhat likely'
levels(export$v_109)[levels(export$v_109 )=='Somehow unlikely'] <- 'Somewhat unlikely'
count <- count(export,v_109) 

ggplot(data = count,
       mapping = aes(x = v_109,y=n)) + 
       xlab("") +
       ylab("Number of participants") +
  geom_col() + theme_bw(base_size=12)
dev.print(pdf,"figures/figure_b2_voting.pdf",width=8, height=4)
```

### Figure B3 (census comparison)
```{r census, fig.width = 10, fig.height = 8}
#Comparison with census as reported in Figure B.3 
export$v_31 <- factor(export$v_31)

count <- count(export,v_31) 
count <- rename(count, Survey = n)

state_population <- read_delim("state_population.csv", 
                        ";", escape_double = FALSE, trim_ws = TRUE)

state_population <- mutate(state_population,Census=n_pop/sum(n_pop)*1019)

state <- dplyr::left_join(state_population,count,by=c("v_31"))

state$Survey[is.na(state$Survey)] <- 0

state <- dplyr::select(state,v_31,Census,Survey)

#Reshape data
library(reshape2)
state<-melt(state)
state <- rename(state,Source=variable)

ggplot(data = state,
       mapping = aes(x = v_31,y=value,fill=Source)) + 
  xlab("") +
  ylab("Number of participants") + coord_flip() +
  geom_bar(stat="identity",position="dodge") + theme_minimal(base_size=16) +
  scale_fill_grey()
dev.print(pdf,"figures/figure_b3_states.pdf",width=10, height=8)
```

### Participants per image pairs group for the whole sample and subgroups
```{r participants}
bureaucrats_control_no <- nrow(filter(export,group_together=="bureaucrats_control"))
police_control_no <- nrow(filter(export,group_together=="police_control"))
bureaucrats_police_no <- nrow(filter(export,group_together=="bureaucrats_police"))

bureaucrats_control_no_a <- nrow(filter(export,group_together=="bureaucrats_control" & anti==1))
police_control_no_a <- nrow(filter(export,group_together=="police_control"& anti==1))
bureaucrats_police_no_a <- nrow(filter(export,group_together=="bureaucrats_police"& anti==1))

bureaucrats_control_no_p <- nrow(filter(export,group_together=="bureaucrats_control"& anti==0))
police_control_no_p <- nrow(filter(export,group_together=="police_control"& anti==0))
bureaucrats_police_no_p <- nrow(filter(export,group_together=="bureaucrats_police"& anti==0))

#Create table B4 
print(xtable(rbind(c(bureaucrats_control_no,police_control_no,bureaucrats_police_no),
              c(bureaucrats_control_no_p,police_control_no_p,bureaucrats_police_no_p),
              c(bureaucrats_control_no_a,police_control_no_a,bureaucrats_police_no_a))),
      file = "tables/table_b4_groups.tex")
```


## Appendix D

### Figure D1 (subgroup analysis: news consumption, Trump supporters)
```{r media pro, fig.width = 11, fig.height = 9}
#Trump supporters
results_news_pro_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Supporter"))

results_news_pro <- amce(chose_stronger~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Supporter"), 
                          cluster=TRUE, respondent.id="id",
                          respondent.varying ="Media",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_media_p <- amce_plot_same(summary(results_news_pro),results_news_pro_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                        "Frequent News Consumers","Infrequent News Consumers","Infrequent-Frequent\n Difference")

results_news_pro_rat_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_rat <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Supporter"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="Media",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_media_rat_p <- amce_plot_same(summary(results_news_pro_rat),results_news_pro_rat_i,"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                                            "Frequent News Consumers","Infrequent News Consumers","Infrequent-Frequent\n Difference")

results_news_pro_app_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_app <- amce(chose_appropiate~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Supporter"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="Media",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate_media_p <- amce_plot_same(summary(results_news_pro_app),results_news_pro_app_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                          "Frequent News Consumers","Infrequent News Consumers","Infrequent-Frequent\n Difference")

results_news_pro_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_protest <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*Media, data=filter(final_perception_df,Trump=="Supporter"), 
                                  cluster=TRUE, respondent.id="id",
                                  respondent.varying = "Media",design=propagandadesign_simple_diss,baselines = baselines)

plot_news_protest_p <- amce_plot_same(summary(results_news_pro_protest),results_news_pro_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                                      "Frequent News Consumers","Infrequent News Consumers","Infrequent-Frequent\n Difference")

#Plot
grid.arrange(plot_strength_media_p,plot_strength_media_rat_p,plot_appropiate_media_p,plot_news_protest_p,ncol = 1)
dev.print(pdf,"figures/figure_d1_media_pro.pdf",width = 11, height = 9)
```

### Figure D2 (subgroup analysis: education, Trump opponents)
```{r education anti, fig.width = 11, fig.height = 9}
##### Education #####
final_perception_df$Education <- as.factor(final_perception_df$education)
levels(final_perception_df$Education) <-  c("Low education","High education")

#Trump opponents
results_news_anti_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Opponent"))

results_news_anti <- amce(chose_stronger~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Opponent"), 
                          cluster=TRUE, respondent.id="id",
                          respondent.varying ="Education",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_Education_a <- amce_plot_same(summary(results_news_anti),results_news_anti_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                        "Low education","High education","High-Low\n Difference")

results_news_anti_rat_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_rat <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Opponent"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="Education",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_Education_rat_a <- amce_plot_same(summary(results_news_anti_rat),results_news_anti_rat_i,"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                                            "Low education","High education","High-Low\n Difference")

results_news_anti_app_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_app <- amce(chose_appropiate~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Opponent"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="Education",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate_Education_a <- amce_plot_same(summary(results_news_anti_app),results_news_anti_app_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                          "Low education","High education","High-Low\n Difference")

results_news_anti_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_protest <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Opponent"), 
                                  cluster=TRUE, respondent.id="id",
                                  respondent.varying = "Education",design=propagandadesign_simple_diss,baselines = baselines)

plot_news_protest_a <- amce_plot_same(summary(results_news_anti_protest),results_news_anti_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                                      "Low education","High education","High-Low\n Difference")

#Plot
grid.arrange(plot_strength_Education_a,plot_strength_Education_rat_a,plot_appropiate_Education_a,plot_news_protest_a,ncol = 1)
dev.print(pdf,"figures/figure_d2_education_anti.pdf",width = 11, height = 9)

```

### Figure D3 (subgroup analysis: education, Trump supporters)
```{r education pro, fig.width = 11, fig.height = 9}
#Trump supporters
results_news_pro_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Supporter"))

results_news_pro <- amce(chose_stronger~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Supporter"), 
                         cluster=TRUE, respondent.id="id",
                         respondent.varying ="Education",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_Education_p <- amce_plot_same(summary(results_news_pro),results_news_pro_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                        "Low education","High education","High-Low\n Difference")

results_news_pro_rat_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_rat <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Supporter"), 
                             cluster=TRUE, respondent.id="id",
                             respondent.varying ="Education",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_Education_rat_p <- amce_plot_same(summary(results_news_pro_rat),results_news_pro_rat_i,"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                                            "Low education","High education","High-Low\n Difference")

results_news_pro_app_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_app <- amce(chose_appropiate~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Supporter"), 
                             cluster=TRUE, respondent.id="id",
                             respondent.varying ="Education",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate_Education_p <- amce_plot_same(summary(results_news_pro_app),results_news_pro_app_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                          "Low education","High education","High-Low\n Difference")

results_news_pro_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_protest <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*Education, data=filter(final_perception_df,Trump=="Supporter"), 
                                 cluster=TRUE, respondent.id="id",
                                 respondent.varying = "Education",design=propagandadesign_simple_diss,baselines = baselines)

plot_news_protest_p <- amce_plot_same(summary(results_news_pro_protest),results_news_pro_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                                      "Low education","High education","High-Low\n Difference")

#Plot
grid.arrange(plot_strength_Education_p,plot_strength_Education_rat_p,plot_appropiate_Education_p,plot_news_protest_p,ncol = 1)
dev.print(pdf,"figures/figure_d3_education_pro.pdf",width = 11, height = 9)
```

### Figure D4 (subgroup analysis: urban/rural, Trump opponents)
```{r urban anti, fig.width = 11, fig.height = 9}
##### Urban #####
final_perception_df$urban <- as.factor(final_perception_df$urban)
levels(final_perception_df$urban) <-  c("Suburban/Rural","Urban")

#Anti
results_news_anti_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Opponent"))

results_news_anti <- amce(chose_stronger~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Opponent"), 
                          cluster=TRUE, respondent.id="id",
                          respondent.varying ="urban",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_urban_a <- amce_plot_same(summary(results_news_anti),results_news_anti_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                        "Suburban/Rural","Urban","Urban-Rural\n Difference")

results_news_anti_rat_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_rat <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Opponent"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="urban",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_urban_rat_a <- amce_plot_same(summary(results_news_anti_rat),results_news_anti_rat_i,"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                                                "Suburban/Rural","Urban","Urban-Rural\n Difference")

results_news_anti_app_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_app <- amce(chose_appropiate~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Opponent"), 
                              cluster=TRUE, respondent.id="id",
                              respondent.varying ="urban",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate_urban_a <- amce_plot_same(summary(results_news_anti_app),results_news_anti_app_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                              "Suburban/Rural","Urban","Urban-Rural\n Difference")

results_news_anti_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Opponent"))
results_news_anti_protest <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Opponent"), 
                                  cluster=TRUE, respondent.id="id",
                                  respondent.varying = "urban",design=propagandadesign_simple_diss,baselines = baselines)

plot_news_protest_a <- amce_plot_same(summary(results_news_anti_protest),results_news_anti_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                                      "Suburban/Rural","Urban","Urban-Rural\n Difference")

#Plot
grid.arrange(plot_strength_urban_a,plot_strength_urban_rat_a,plot_appropiate_urban_a,plot_news_protest_a,ncol = 1)
dev.print(pdf,"figures/figure_d4_urban_anti.pdf",width = 11, height = 9)
```

### Figure D5 (subgroup analysis: urban/rural, Trump supporters)
```{r urban pro, fig.width = 11, fig.height = 9}
#Pro group
results_news_pro_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Supporter"))

results_news_pro <- amce(chose_stronger~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Supporter"), 
                         cluster=TRUE, respondent.id="id",
                         respondent.varying ="urban",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_urban_p <- amce_plot_same(summary(results_news_pro),results_news_pro_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                            "Suburban/Rural","Urban","Urban-Rural\n Difference")

results_news_pro_rat_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_rat <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Supporter"), 
                             cluster=TRUE, respondent.id="id",
                             respondent.varying ="urban",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_urban_rat_p <- amce_plot_same(summary(results_news_pro_rat),results_news_pro_rat_i,"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                                                "Suburban/Rural","Urban","Urban-Rural\n Difference")

results_news_pro_app_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_app <- amce(chose_appropiate~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Supporter"), 
                             cluster=TRUE, respondent.id="id",
                             respondent.varying ="urban",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate_urban_p <- amce_plot_same(summary(results_news_pro_app),results_news_pro_app_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                              "Suburban/Rural","Urban","Urban-Rural\n Difference")

results_news_pro_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Supporter"))
results_news_pro_protest <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*urban, data=filter(final_perception_df,Trump=="Supporter"), 
                                 cluster=TRUE, respondent.id="id",
                                 respondent.varying = "urban",design=propagandadesign_simple_diss,baselines = baselines)

plot_news_protest_p <- amce_plot_same(summary(results_news_pro_protest),results_news_pro_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                                      "Suburban/Rural","Urban","Urban-Rural\n Difference")

#Plot
grid.arrange(plot_strength_urban_p,plot_strength_urban_rat_p,plot_appropiate_urban_p,plot_news_protest_p,ncol = 1)
dev.print(pdf,"figures/figure_d5_urban_pro.pdf",width = 11, height = 9)
```

### Figure D6 (subgroup analysis: ethnic groups, Trump opponents)
```{r black pro, fig.width = 11, fig.height = 9}
##### Ethnic groups detailed for appendix D ######
final_perception_df <- final_perception_df %>% mutate(ethnic_sig_reduced = case_when(ethnic_group_sig %in% c("African American") ~ "Black",
                                                                                     ethnic_group_sig %in% c("Latino") ~ "Latino",
                                                                                     ethnic_group_sig %in% c("White", "Other") ~ "Other"))


final_perception_df$ethnic_sig_reduced <- as.factor(final_perception_df$ethnic_sig_reduced)

#Anti (African American as moderation)
results_group_cs <- amce(chose_stronger~  picture_dis+picture_dis*ethnic_sig_reduced, data=final_perception_df, 
                      cluster=TRUE, respondent.id="id",
                      respondent.varying ="ethnic_sig_reduced",design=propagandadesign_simple_diss,baselines = baselines)

plot_group_cs <- amce_plot_2(summary(results_group_cs),"(a) Strength","Difference in Strength Perception (Forced Choice)",
                        "Unconditional","Black","Latino","Other")

results_group_cs_rat <- amce(rating_stronger_numeric_z ~  picture_dis+picture_dis*ethnic_sig_reduced, data=final_perception_df, 
                          cluster=TRUE, respondent.id="id",
                          respondent.varying ="ethnic_sig_reduced",design=propagandadesign_simple_diss,baselines = baselines)

plot_group_cs_rat <- amce_plot_2(summary(results_group_cs_rat),"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                                 "Unconditional","Black","Latino","Other")

results_group_ca <- amce(chose_appropiate~  picture_dis+picture_dis*ethnic_sig_reduced, data=final_perception_df, 
                      cluster=TRUE, respondent.id="id",
                      respondent.varying ="ethnic_sig_reduced",design=propagandadesign_simple_diss,baselines = baselines)

plot_group_ca <- amce_plot_2(summary(results_group_ca),"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                             "Unconditional","Black","Latino","Other")

results_group_pw <- amce(rating_protest_numeric_z~  picture_dis+picture_dis*ethnic_sig_reduced, data=final_perception_df, 
                      cluster=TRUE, respondent.id="id",
                      respondent.varying ="ethnic_sig_reduced",design=propagandadesign_simple_diss,baselines = baselines)
plot_group_pw <- amce_plot_2(summary(results_group_pw),"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                           "Unconditional","Black","Latino","Other")

#Plot
grid.arrange(plot_group_cs,plot_group_cs_rat,plot_group_ca,plot_group_pw,ncol = 1)
dev.print(pdf,"figures/figure_d6_group.pdf",width = 11, height = 9)
```

### What else predicts Trump opponents? (As reported in Appendix D 2.4)

```{r appendix D2.4}
anti <- lm(anti~democrat+male+republican+latino+aa+white+less+
           highed+suburban+urban+news_almnever+factor(v_31)+factor(v_21),data=export)

#Add step-wise procedure
selectedAnti <- step(anti)

texreg::texreg(list(anti,selectedAnti),file = "tables/table_d3_anti_group.tex",
       custom.coef.map = list('(Intercept)'="Intercept",'democrat'="Democrat",'republican'="Republican",'male'="Male",
                              'factor(v_21)21 - 29' = "Age (21-29)",'factor(v_21)30 - 39' = "
                              Age (30-39)", 'factor(v_21)40 - 49' = "Age (40-49)",
                              'factor(v_21)50 - 59' = "Age (50-59)", 'factor(v_21)Older than 60'=
                                "Age (older than 60)", 'latino'="Latino",'aa'="African American",
                              'white'="Caucasian",'highed'="Higher education",
                              'master'="Graduate degree or higher",'suburban'="Sub-urban",
                              'urban'="Urban", "news_almnever" ="Infrequent news consumer"))

```



## Appendix E: Sensitivity Analyses

### Figure E1 (main results with check for profile ordering effects)
```{r profile ordering, fig.width = 11, fig.height = 9}
#### Profile order####
final_perception_df$profile <- as.factor(final_perception_df$profile)

results_strength_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*profile, data=final_perception_df)

results_strength <- amce(chose_stronger~  picture_dis+picture_dis*profile, data=final_perception_df, 
                         cluster=TRUE, respondent.id="id",
                         respondent.varying ="profile",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength <- amce_plot_same(summary(results_strength),results_strength_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                "Profile 1","Profile 2","Difference\n Profile 2-Profile 1")


results_strength_rating_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*profile, data=final_perception_df)

results_strength_rating <- amce(rating_stronger_numeric_z ~  picture_dis+picture_dis*profile, data=final_perception_df, 
                                cluster=TRUE, respondent.id="id",
                                respondent.varying ="profile",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating <- amce_plot_same(summary(results_strength_rating),results_strength_rating_i,"(b) Political Strength","Difference in Strength Perception (Rating)",
                                       "Profile 1","Profile 2","Difference\n Profile 2-Profile 1")

results_appropiate_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*profile, data=final_perception_df)

results_appropiate <- amce(chose_appropiate~  picture_dis+picture_dis*profile, data=final_perception_df, 
                           cluster=TRUE, respondent.id="id",
                           respondent.varying ="profile",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate <- amce_plot_same(summary(results_appropiate),results_appropiate_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                  "Profile 1","Profile 2","Difference\n Profile 2-Profile 1")

results_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*profile, data=final_perception_df)

results_protest <- amce(rating_protest_numeric_z ~  picture_dis+picture_dis*profile, data=final_perception_df, 
                        cluster=TRUE, respondent.id="id",
                        respondent.varying ="profile",design=propagandadesign_simple_diss,baselines = baselines)
plot_protest <- amce_plot_same(summary(results_protest),results_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                               "Profile 1","Profile 2","Difference\n Profile 2-Profile 1")


grid.arrange(plot_strength,plot_strength_rating,plot_appropiate,plot_protest,ncol = 1)
dev.print(pdf,"figures/figure_e1_profiles.pdf",width=11, height=9)
```

### Figure E2 (main results with aggregated treatment groups)
```{r aggregated, fig.width = 11, fig.height = 9}
### Aggregated Results #####

results_strength_i <- lm_robust(chose_stronger~  picture+picture*Trump, data=final_perception_df)

results_strength <- amce(chose_stronger~  picture+picture*Trump, data=final_perception_df, 
                         cluster=TRUE, respondent.id="id",
                         respondent.varying ="Trump",design=propagandadesign_simple,baselines = baselines)
plot_strength <- amce_plot_agg(summary(results_strength),results_strength_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


results_strength_rating_i <- lm_robust(rating_stronger_numeric_z~  picture+picture*Trump, data=final_perception_df)

results_strength_rating <- amce(rating_stronger_numeric_z ~  picture+picture*Trump, data=final_perception_df, 
                                cluster=TRUE, respondent.id="id",
                                respondent.varying ="Trump",design=propagandadesign_simple,baselines = baselines)
plot_strength_rating <- amce_plot_agg(summary(results_strength_rating),results_strength_rating_i,"(b) Political Strength","Difference in Strength Perception (Rating)",
                                       "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_appropiate_i <- lm_robust(chose_appropiate~  picture+picture*Trump, data=final_perception_df)

results_appropiate <- amce(chose_appropiate~  picture+picture*Trump, data=final_perception_df, 
                           cluster=TRUE, respondent.id="id",
                           respondent.varying ="Trump",design=propagandadesign_simple,baselines = baselines)
plot_appropiate <- amce_plot_agg(summary(results_appropiate),results_appropiate_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                  "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_protest_i <- lm_robust(rating_protest_numeric_z~  picture+picture*Trump, data=final_perception_df)

results_protest <- amce(rating_protest_numeric_z ~  picture+picture*Trump, data=final_perception_df, 
                        cluster=TRUE, respondent.id="id",
                        respondent.varying ="Trump",design=propagandadesign_simple,baselines = baselines)
plot_protest <- amce_plot_agg(summary(results_protest),results_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                               "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


grid.arrange(plot_strength,plot_strength_rating,plot_appropiate,plot_protest,ncol = 1)
dev.print(pdf,"figures/figure_e2_results.pdf",width=11, height=9)
```

### Figure E3 (main results with undecided group)
```{r undecided, fig.width = 11, fig.height = 9}
#### Adding an Undecided Group ####

final_perception_df <- final_perception_df %>% mutate(
  Trump_cat=case_when(stance %in% c("Somehow unlikely","Somehow likely") ~ "Undecided",
                      stance %in% c("Unlikely","Very unlikely") ~ "Opponent",
                      stance %in% c("Likely","Very likely") ~ "Supporter")
)

final_perception_df$Trump_cat <- factor(final_perception_df$Trump_cat,
                                        levels = c("Opponent","Supporter","Undecided"))

results_cat_cs <- amce(chose_stronger~  picture_dis+picture_dis*Trump_cat, data=final_perception_df,
                  cluster=TRUE, respondent.id="id",
                  respondent.varying ="Trump_cat",design=propagandadesign_simple_diss,baselines = baselines)
plot_cat_cs <- amce_plot_2(summary(results_cat_cs),"(a) Strength","Difference in Strength Perception (Forced Choice)",
                             "Unconditional","Opponent","Supporter","Undecided")

results_cat_cs_rating <- amce(rating_stronger_numeric_z~  picture_dis+picture_dis*Trump_cat, data=final_perception_df,
                       cluster=TRUE, respondent.id="id",
                       respondent.varying ="Trump_cat",design=propagandadesign_simple_diss,baselines = baselines)
plot_cat_cs_rating <- amce_plot_2(summary(results_cat_cs_rating),"(b) Political Strength","Difference in Political Strength Perception (Rating)",
                           "Unconditional","Opponent","Supporter","Undecided")


results_cat_ca<- amce(chose_appropiate~  picture_dis+picture_dis*Trump_cat, data=final_perception_df,
                  cluster=TRUE, respondent.id="id",
                  respondent.varying ="Trump_cat",design=propagandadesign_simple_diss,baselines = baselines)
plot_cat_ca <- amce_plot_2(summary(results_cat_ca),"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                           "Unconditional","Opponent","Supporter","Undecided")


results_cat_pw<- amce(rating_protest_numeric_z ~  picture_dis+picture_dis*Trump_cat, data=final_perception_df, 
                  cluster=TRUE, respondent.id="id",
                  respondent.varying ="Trump_cat",design=propagandadesign_simple_diss,baselines = baselines)
plot_cat_pw <- amce_plot_2(summary(results_cat_pw),"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                           "Unconditional","Opponent","Supporter","Undecided")

#Plot
grid.arrange(plot_cat_cs,plot_cat_cs_rating,plot_cat_ca,plot_cat_pw,ncol = 1)
dev.print(pdf,"figures/figure_e3_undecided.pdf",width=11, height=9)
```

### Figure E4 (main results with dropping fastest respondents)
```{r fast, fig.width = 11, fig.height = 9}
#### Fastest Respondents ####
results_strength_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*Trump, data=filter(final_perception_df,
                                                                                            duration > quantile(final_perception_df$duration,0.05)))

results_strength <- amce(chose_stronger~  picture_dis+picture_dis*Trump, data=filter(final_perception_df,                                                                                           duration > quantile(final_perception_df$duration,0.05)), 
                         cluster=TRUE, respondent.id="id",
                         respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength <- amce_plot_same(summary(results_strength),results_strength_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


results_strength_rating_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Trump, data=filter(final_perception_df,                                                                                           duration > quantile(final_perception_df$duration,0.05)))

results_strength_rating <- amce(rating_stronger_numeric_z ~  picture_dis+picture_dis*Trump, data=filter(final_perception_df,                                                                                           duration > quantile(final_perception_df$duration,0.05)), 
                                cluster=TRUE, respondent.id="id",
                                respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating <- amce_plot_same(summary(results_strength_rating),results_strength_rating_i,"(b) Political Strength","Difference in Strength Perception (Rating)",
                                       "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_appropiate_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*Trump, data=filter(final_perception_df,                                                                                           duration > quantile(final_perception_df$duration,0.05)))

results_appropiate <- amce(chose_appropiate~  picture_dis+picture_dis*Trump, data=filter(final_perception_df,                                                                                           duration > quantile(final_perception_df$duration,0.05)), 
                           cluster=TRUE, respondent.id="id",
                           respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate <- amce_plot_same(summary(results_appropiate),results_appropiate_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                  "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Trump, data=filter(final_perception_df,                                                                                           duration > quantile(final_perception_df$duration,0.05)))

results_protest <- amce(rating_protest_numeric_z ~  picture_dis+picture_dis*Trump, data=filter(final_perception_df,                                                                                           duration > quantile(final_perception_df$duration,0.05)), 
                        cluster=TRUE, respondent.id="id",
                        respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_protest <- amce_plot_same(summary(results_protest),results_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                               "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


grid.arrange(plot_strength,plot_strength_rating,plot_appropiate,plot_protest,ncol = 1)
dev.print(pdf,"figures/figure_e4_fast.pdf",width=11, height=9)
```

### Figure E5 (testing for framing effects) and further framing analyses

```{r framing, fig.width = 11, fig.height = 9}
#### Framing Analyses ####

#Only consider C-T pairs

#562-834 (t1-t2) #pro
#1641-2038 (t1-t2) #anti


#Only considering CT combinations (alternatively create dummy for these combinations)
df_ct <- final_perception_df[c(1:562,835:1640),]

results_strength_i <- lm_robust(chose_stronger~  picture_dis+picture_dis*Trump, data=df_ct)

results_strength <- amce(chose_stronger~  picture_dis+picture_dis*Trump, data=df_ct, 
                         cluster=TRUE, respondent.id="id",
                         respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength <- amce_plot_same(summary(results_strength),results_strength_i,"(a) Strength","Difference in Strength Perception (Forced Choice)",
                                "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


results_strength_rating_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Trump, data=df_ct)

results_strength_rating <- amce(rating_stronger_numeric_z ~  picture_dis+picture_dis*Trump, data=df_ct, 
                                cluster=TRUE, respondent.id="id",
                                respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating <- amce_plot_same(summary(results_strength_rating),results_strength_rating_i,"(b) Political Strength","Difference in Strength Perception (Rating)",
                                       "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_appropiate_i <- lm_robust(chose_appropiate~  picture_dis+picture_dis*Trump, data=df_ct)

results_appropiate <- amce(chose_appropiate~  picture_dis+picture_dis*Trump, data=df_ct, 
                           cluster=TRUE, respondent.id="id",
                           respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_appropiate <- amce_plot_same(summary(results_appropiate),results_appropiate_i,"(c) Appropriateness","Difference in Appropriateness Perception (Forced Choice)",
                                  "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_protest_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Trump, data=df_ct)

results_protest <- amce(rating_protest_numeric_z ~  picture_dis+picture_dis*Trump, data=df_ct, 
                        cluster=TRUE, respondent.id="id",
                        respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_protest <- amce_plot_same(summary(results_protest),results_protest_i,"(d) Mobilization Potential","Difference in Mobilization Potential (Rating)",
                               "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


grid.arrange(plot_strength,plot_strength_rating,plot_appropiate,plot_protest,ncol = 1)
dev.print(pdf,"figures/figure_e5_main_results_ct.pdf",width=11, height=9)

adjust_df <- function(substract){
final_perception_pro_c <- final_perception_df[1:562,]
final_perception_pro_t <-final_perception_df[563:834,]

police_control_pro <- filter(final_perception_pro_c,picture_dis=="police")
police_bureaucrats_pro <- filter(final_perception_pro_t,picture_dis=="police")

police_strength_pro <- t.test(police_control_pro$rating_stronger_numeric_z,police_bureaucrats_pro$rating_stronger_numeric_z)
#Police image rather as politically stronger when together with control image (<0.01)
police_protest_pro <- t.test(police_control_pro$rating_protest_numeric_z,police_bureaucrats_pro$rating_protest_numeric_z)
#t.test(police_control_pro$never_protest,police_bureaucrats_pro$never_protest)


bureaucrats_control_pro <- filter(final_perception_pro_c,picture_dis=="bureaucrats")
bureaucrats_police_pro <- filter(final_perception_pro_t,picture_dis=="bureaucrats")

bureaucrats_strength_pro <- t.test(bureaucrats_control_pro$rating_stronger_numeric_z,bureaucrats_police_pro$rating_stronger_numeric_z)
bureaucrats_protest_pro <- t.test(bureaucrats_control_pro$rating_protest_numeric_z,bureaucrats_police_pro$rating_protest_numeric_z)


if (substract==1){
#Adjust for error in data (subtract mean difference from higher rating)
police_control_pro$rating_stronger_numeric_z<- police_control_pro$rating_stronger_numeric_z-(police_strength_pro$estimate[2]-police_strength_pro$estimate[1])
bureaucrats_control_pro$rating_stronger_numeric_z <- bureaucrats_control_pro$rating_stronger_numeric_z-(bureaucrats_strength_pro$estimate[1]-bureaucrats_strength_pro$estimate[2])

police_bureaucrats_pro$rating_protest_numeric_z<- police_bureaucrats_pro$rating_protest_numeric_z-(police_protest_pro$estimate[2]-police_protest_pro$estimate[1])
bureaucrats_control_pro$rating_protest_numeric_z <- bureaucrats_control_pro$rating_protest_numeric_z-(bureaucrats_protest_pro$estimate[1]-bureaucrats_protest_pro$estimate[2])
}

if (substract==0){
#Adjust for error in data (add mean difference to lower rating)
police_bureaucrats_pro$rating_stronger_numeric_z<- police_bureaucrats_pro$rating_stronger_numeric_z+(police_strength_pro$estimate[1]-police_strength_pro$estimate[2])
bureaucrats_police_pro$rating_stronger_numeric_z <- bureaucrats_police_pro$rating_stronger_numeric_z+(bureaucrats_strength_pro$estimate[1]-bureaucrats_strength_pro$estimate[2])

police_control_pro$rating_protest_numeric_z<- police_control_pro$rating_protest_numeric_z+(police_protest_pro$estimate[2]-police_protest_pro$estimate[1])
bureaucrats_police_pro$rating_protest_numeric_z <- bureaucrats_police_pro$rating_protest_numeric_z+(bureaucrats_protest_pro$estimate[1]-bureaucrats_protest_pro$estimate[2])
}

final_perception_anti_c <- final_perception_df[835:1640,]
final_perception_anti_t <-final_perception_df[1641:2038,]

police_control_anti <- filter(final_perception_anti_c,picture_dis=="police")
police_bureaucrats_anti <- filter(final_perception_anti_t,picture_dis=="police")

police_strength_anti <- t.test(police_control_anti$rating_stronger_numeric_z,police_bureaucrats_anti$rating_stronger_numeric_z)
police_protest_anti <- t.test(police_control_anti$rating_protest_numeric_z,police_bureaucrats_anti$rating_protest_numeric_z)



bureaucrats_control_anti <- filter(final_perception_anti_c,picture_dis=="bureaucrats")
bureaucrats_police_anti <- filter(final_perception_anti_t,picture_dis=="bureaucrats")

bureaucrats_strenght_anti <- t.test(bureaucrats_control_anti$rating_stronger_numeric_z,bureaucrats_police_anti$rating_stronger_numeric_z)
bureaucrats_protest_anti <- t.test(bureaucrats_control_anti$rating_protest_numeric_z,bureaucrats_police_anti$rating_protest_numeric_z)

if (substract==1){
#Adjust for error in data (subtract mean difference from higher rating)
police_control_anti$rating_stronger_numeric_z<- police_control_anti$rating_stronger_numeric_z-(police_strength_anti$estimate[1]-police_strength_anti$estimate[2])
bureaucrats_police_anti$rating_stronger_numeric_z <- bureaucrats_police_anti$rating_stronger_numeric_z-(bureaucrats_strenght_anti$estimate[2]-bureaucrats_strenght_anti$estimate[1])

police_control_anti$rating_protest_numeric_z<- police_control_anti$rating_protest_numeric_z-(police_protest_anti$estimate[1]-police_protest_anti$estimate[2])
bureaucrats_control_anti$rating_protest_numeric_z <- bureaucrats_control_anti$rating_protest_numeric_z-(bureaucrats_protest_anti$estimate[1]-bureaucrats_protest_anti$estimate[2])
}

if (substract==0){
  #Adjust for error in data (subtract mean difference from higher rating)
  police_bureaucrats_anti$rating_stronger_numeric_z<- police_bureaucrats_anti$rating_stronger_numeric_z+(police_strength_anti$estimate[1]-police_strength_anti$estimate[2])
  bureaucrats_control_anti$rating_stronger_numeric_z <- bureaucrats_control_anti$rating_stronger_numeric_z+(bureaucrats_strenght_anti$estimate[2]-bureaucrats_strenght_anti$estimate[1])
  
  police_bureaucrats_anti$rating_protest_numeric_z<- police_bureaucrats_anti$rating_protest_numeric_z+(police_protest_anti$estimate[1]-police_protest_anti$estimate[2])
  bureaucrats_police_anti$rating_protest_numeric_z <- bureaucrats_police_anti$rating_protest_numeric_z+(bureaucrats_protest_anti$estimate[1]-bureaucrats_protest_anti$estimate[2])
}


#Investigate whether rating is different for control image depending on different treatment image

final_perception_pro_c1 <- final_perception_pro_c[1:286,] #Control/Bureaucrats
final_perception_pro_c2 <- final_perception_pro_c[287:562,] #Control/Police

control_pro_c1 <- filter(final_perception_pro_c1,picture_dis=="control")
control_pro_c2 <- filter(final_perception_pro_c2,picture_dis=="control")

control_strenght_pro <- t.test(control_pro_c1$rating_stronger_numeric_z,control_pro_c2$rating_stronger_numeric_z)
control_protest_pro <- t.test(control_pro_c1$rating_protest_numeric_z,control_pro_c2$rating_protest_numeric_z)
#t.test(control_pro_c1$never_protest,control_pro_c2$never_protest)


if (substract==1){
#Adjust for error in data (subtract mean difference from higher rating)
control_pro_c2$rating_stronger_numeric_z<- control_pro_c2$rating_stronger_numeric_z-(control_strenght_pro$estimate[2]-control_strenght_pro$estimate[1])
control_pro_c1$rating_protest_numeric_z <- control_pro_c1$rating_protest_numeric_z-(control_protest_pro$estimate[1]-control_protest_pro$estimate[2])
}

if (substract==0){
  #Adjust for error in data (subtract mean difference from higher rating)
  control_pro_c1$rating_stronger_numeric_z<- control_pro_c1$rating_stronger_numeric_z+(control_strenght_pro$estimate[2]-control_strenght_pro$estimate[1])
  control_pro_c2$rating_protest_numeric_z <- control_pro_c2$rating_protest_numeric_z+(control_protest_pro$estimate[1]-control_protest_pro$estimate[2])
}



final_perception_anti_c1 <- final_perception_anti_c[1:410,] #Bureaucrats/Control
final_perception_anti_c2 <- final_perception_anti_c[411:806,] #Police/Control

control_anti_c1 <- filter(final_perception_anti_c1,picture_dis=="control")
control_anti_c2 <- filter(final_perception_anti_c2,picture_dis=="control")

control_strenght_anti <- t.test(control_anti_c1$rating_stronger_numeric_z,control_anti_c2$rating_stronger_numeric_z)
control_protest_anti <- t.test(control_anti_c1$rating_protest_numeric_z,control_anti_c2$rating_protest_numeric_z)
#Borderline sign. when anti-participants see the control image together with the police image, they are more likely to 
#rate the protest outcome lower for the control image,
#we may thus overestimate the positive relative effect on protest willingness?

if (substract==1){
#Adjust for diff evaluation in data (subtract mean difference from higher rating)
control_anti_c2$rating_stronger_numeric_z<- control_anti_c2$rating_stronger_numeric_z-(control_strenght_anti$estimate[2]-control_strenght_anti$estimate[1])
control_anti_c1$rating_protest_numeric_z <- control_anti_c1$rating_protest_numeric_z-(control_protest_anti$estimate[1]-control_protest_anti$estimate[2])
}

if (substract==0){
  #Adjust for diff evaluation in data (subtract mean difference from higher rating)
  control_anti_c1$rating_stronger_numeric_z<- control_anti_c1$rating_stronger_numeric_z+(control_strenght_anti$estimate[2]-control_strenght_anti$estimate[1])
  control_anti_c2$rating_protest_numeric_z <- control_anti_c2$rating_protest_numeric_z+(control_protest_anti$estimate[1]-control_protest_anti$estimate[2])
}

final_perception_df_adj <- bind_rows(police_bureaucrats_pro,police_control_pro,bureaucrats_police_pro,bureaucrats_control_pro,
  police_bureaucrats_anti,police_control_anti,bureaucrats_police_anti,bureaucrats_control_anti,
                                     control_pro_c1,control_pro_c2,control_anti_c1,control_anti_c2)


#When anti-participants see the control image together with the police image, they are more likely to choose the
#the never protest answer, we may thus overestimate the positive relative effect on protest willingness?
tab_strength_pro <- rbind(c("Police (Reference)","Police (Bureaucrats)",""),
                          c(round(police_strength_pro$estimate,2),round(police_strength_pro$p.value,2)),
                          c("Bureaucrats (Reference)","Bureaucrats (Police)",""),
                          c(round(bureaucrats_strength_pro$estimate,2),round(bureaucrats_strength_pro$p.value,2)),
                          c("Reference (Bureaucrats)","Reference (Police)",""),
                          c(round(control_strenght_pro$estimate,2),round(control_strenght_pro$p.value,2)))

tab_strength_anti <- rbind(c("Police (Reference)","Police (Bureaucrats)",""),
                           c(round(police_strength_anti$estimate,2),round(police_strength_anti$p.value,2)),
                           c("Bureaucrats (Reference)","Bureaucrats (Police)",""),
                           c(round(bureaucrats_strenght_anti$estimate,2),round(bureaucrats_strenght_anti$p.value,2)),
                           c("Reference (Bureaucrats)","Reference (Police)",""),
                           c(round(control_strenght_anti$estimate,2),round(control_strenght_anti$p.value,2)))

test_strength <- rbind(tab_strength_pro,tab_strength_anti)

tab_protest_pro <- rbind(c("Police (Reference)","Police (Bureaucrats)",""),
                         c(round(police_protest_pro$estimate,2),round(police_protest_pro$p.value,2)),
                         c("Bureaucrats (Reference)","Bureaucrats (Police)",""),
                         c(round(bureaucrats_protest_pro$estimate,2),round(bureaucrats_protest_pro$p.value,2)),
                         c("Reference (Bureaucrats)","Reference (Police)",""),
                         c(round(control_protest_pro$estimate,2),round(control_protest_pro$p.value,2)))

tab_protest_anti <- rbind(c("Police (Reference)","Police (Bureaucrats)",""),
                          c(round(police_protest_anti$estimate,2),round(police_protest_anti$p.value,2)),
                          c("Bureaucrats (Reference)","Bureaucrats (Police)",""),
                          c(round(bureaucrats_protest_anti$estimate,2),round(bureaucrats_protest_anti$p.value,2)),
                          c("Reference (Bureaucrats)","Reference (Police)",""),
                          c(round(control_protest_anti$estimate,2),round(control_protest_anti$p.value,2)))

test_protest <- rbind(tab_protest_pro,tab_protest_anti)


return(list(final_perception_df_adj,test_strength,test_protest))
}


adjust_substract <- adjust_df(substract=1)
adjust_add <- adjust_df(substract=0)

#Report t tests
xtable(adjust_substract[[2]])

xtable(adjust_substract[[3]])
```

### Figures E6 and E7 (results with models adjusted for potential biases)
```{r adjusted, fig.width = 11, fig.height = 6.5}
#Run models again adjusting for potential biases#


# Outcomes for political strength

results_rating_i <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Trump, data=final_perception_df)

results_rating <- amce(rating_stronger_numeric_z ~  picture_dis+picture_dis*Trump, data=final_perception_df, 
                                cluster=TRUE, respondent.id="id",
                                respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating <- amce_plot_same(summary(results_rating),results_rating_i,"(a) Political Strength","Difference in Strength Perception (Rating, Original)",
                                       "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_rating_i_sub <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Trump, data=adjust_substract[[1]])

results_rating_sub <- amce(rating_stronger_numeric_z ~  picture_dis+picture_dis*Trump, data=adjust_substract[[1]], 
                       cluster=TRUE, respondent.id="id",
                       respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating_sub1 <- amce_plot_same(summary(results_rating_sub),results_rating_i_sub,"(b) Political Strength","Difference in Strength Perception (Rating, Downward Adjusted)",
                                       "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_rating_i_sub <- lm_robust(rating_stronger_numeric_z~  picture_dis+picture_dis*Trump, data=adjust_add[[1]])

results_rating_sub <- amce(rating_stronger_numeric_z ~  picture_dis+picture_dis*Trump, data=adjust_add[[1]], 
                           cluster=TRUE, respondent.id="id",
                           respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating_sub2 <- amce_plot_same(summary(results_rating_sub),results_rating_i_sub,"(c) Political Strength","Difference in Strength Perception (Rating, Upward Adjusted)",
                                           "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")


grid.arrange(plot_strength_rating,plot_strength_rating_sub1,plot_strength_rating_sub2,ncol = 1)
dev.print(pdf,"figures/figure_e6_strength_adj.pdf",width=11, height=6.5)


results_rating_i <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Trump, data=final_perception_df)

results_rating <- amce(rating_protest_numeric_z ~  picture_dis+picture_dis*Trump, data=final_perception_df, 
                       cluster=TRUE, respondent.id="id",
                       respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating <- amce_plot_same(summary(results_rating),results_rating_i,"(a) Mobilization potential","Difference in Strength Perception (Rating, Original)",
                                       "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_rating_i_sub <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Trump, data=adjust_substract[[1]])

results_rating_sub <- amce(rating_protest_numeric_z ~  picture_dis+picture_dis*Trump, data=adjust_substract[[1]], 
                           cluster=TRUE, respondent.id="id",
                           respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating_sub1 <- amce_plot_same(summary(results_rating_sub),results_rating_i,"(b) Mobilization potential","Difference in Strength Perception (Rating, Downward Adjusted)",
                                           "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

results_rating_i_sub <- lm_robust(rating_protest_numeric_z~  picture_dis+picture_dis*Trump, data=adjust_add[[1]])

results_rating_sub <- amce(rating_protest_numeric_z ~  picture_dis+picture_dis*Trump, data=adjust_add[[1]], 
                           cluster=TRUE, respondent.id="id",
                           respondent.varying ="Trump",design=propagandadesign_simple_diss,baselines = baselines)
plot_strength_rating_sub2 <- amce_plot_same(summary(results_rating_sub),results_rating_i,"(c) Mobilization potential","Difference in Strength Perception (Rating, Upward Adjusted)",
                                           "Trump Supporters","Trump Opponents","Difference\n Opponents-Supporters")

grid.arrange(plot_strength_rating,plot_strength_rating_sub1,plot_strength_rating_sub2,ncol = 1)
dev.print(pdf,"figures/figure_e7_protest_adj.pdf",width=11, height=6.5)

```

## Power Analysis
```{r power}

#### Power Tests ####
#(according to de Bekker-Grob, E.W., Donkers, B., Jonker, M.F. et al. Patient (2015) 8: 373. https://doi.org/10.1007/s40271-015-0118-z##)
#Table E1 and E2 added manually

# Set significance level
#test_alpha=0.025  # p=0.05 (two-sided test)
test_alpha=0.05  # p=0.05 (one-sided test)
z_one_minus_alpha<-qnorm(1-test_alpha)

# Set power level
#test_beta=0.1  # 90%
test_beta=0.2  # 80%
z_one_minus_beta <- qnorm(1-test_beta)

# Specify design matrix
# - operationalize as simple choice task between two alternatives (two pictures shown)
# - possible combinations T1/C, T2/C, T1/T2
# - formalize as attribute "image" with levels
#     C: baseline, not in design matrix
#     T1: bureaucrat image (1:used, 0: not used)
#     T2: police image (1: used, 0: not used)
# - lines in matrix correspond to line1: image1, line2: image 2
#   i.e. line1: 1, 0, line 2: 0, 0 of a blocks means T1/C
# - need three blocks of two lines, i.e., possible choice sets
design = matrix(c(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1), nrow=6, ncol=2)

# Corresponding characteristics of DCE design
nalts = 2  # no. of choice alternatives given to participants (size of choice set)
nchoices = 3  # total number of choice sets in design (3 pairwise comparisons)

# Beliefs about parameters are based on model estimates
# - effects of each treatment image vs. control
parameters = c(0.092857,0.145266)
ncoefficients = length(parameters)  # no. of parameters

# Calculate information matrix
info_mat = matrix(rep(0,ncoefficients*ncoefficients), ncoefficients, ncoefficients) 
# compute exp(design matrix times initial parameter values) 
exputilities = exp(design%*%parameters)

# loop over all choice sets
for (k_set in 1:nchoices) {
  # select alternatives in the choice set
  alternatives = ((k_set-1)*nalts+1) : (k_set*nalts)
  # obtain vector of choice shares within the choice set
  p_set = exputilities[alternatives]/sum(exputilities[alternatives])
  # also put these probabilities on the diagonal of a matrix that only contains zeros
  p_diag = diag(p_set)
  # compute middle term P-pp’
  middle_term = p_diag-p_set%o%p_set
  # pre- and postmultiply with the Xs from the design matrix for the alternatives in this choice set
  full_term = t(design[alternatives,])%*%middle_term%*%design[alternatives,]
  # Add contribution of this choice set to the information matrix
  info_mat = info_mat+full_term 
} # end of loop over choice sets
#get the inverse of the information matrix (i.e., gets the variance-covariance matrix)
sigma_beta = solve(info_mat,diag(ncoefficients)) 

#set effectsize
#effectsize = parameters
#N = ((z_one_minus_beta + z_one_minus_alpha)*sqrt(diag(sigma_beta))/abs(effectsize))^2
# number of observations is participants times number of alternatives they see
#participants = N/nalts

# calculate MDE - fulll sample
participants = 1019
N = participants * nalts
MDE = (z_one_minus_beta + z_one_minus_alpha)*sqrt(diag(sigma_beta))/sqrt(N)

# calculate MDE - sub-groups
supporters = 417
opponents = 602
N_supporters = supporters * nalts
N_opponents = opponents * nalts
MDE_supporter = (z_one_minus_beta + z_one_minus_alpha)*sqrt(diag(sigma_beta))/sqrt(N_supporters)
MDE_opponents = (z_one_minus_beta + z_one_minus_alpha)*sqrt(diag(sigma_beta))/sqrt(N_opponents)

```